package yuku.ambilwarna;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;


public class ColorHistoryAdapter extends BaseAdapter {

	private Context mContext;

	ArrayList<String> colorArray;
	String [] colorArr;

	// Constructor
	public ColorHistoryAdapter(Context c, ArrayList<String> usedColors){
		mContext = c;	
		colorArray = usedColors;	
		colorArr = new String[colorArray.size()];
		colorArr  =  colorArray.toArray(colorArr);
	}

	public int getCount() {
		return colorArr.length;
	}

	public String getItem(int position) {
		return colorArr[position];
	}

	public String getIcon(int position) {
		return colorArr[position];
	}

	public String getUnitCost(int position) {
		return colorArr[position];
	}

	public String getQty(int position) {
		return colorArr[position];
	}
	
	public long getItemId(int position) {
		return 0;
	}
	
	public View getView(final int position, View convertView, ViewGroup parent) {
		//View v = null;			
		if(convertView==null){
			LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = li.inflate(R.layout.colortemplate, null);
		}			
		ImageView iv = (ImageView) convertView.findViewById(R.id.colorBox);
		iv.setAdjustViewBounds(true);
	    String color =  colorArr[position].trim();
	    int myColor = Color.parseColor(color);
		iv.setBackgroundColor(myColor);				
		iv.setTag(myColor);
		convertView.setId(myColor);	
		return convertView;
	}
}